package com.gravata.enigma.activities;

import android.os.Bundle;
import android.preference.PreferenceActivity;
import android.widget.Toast;

import com.gravata.enigma.R;

public class ConfiguracaoActivity extends PreferenceActivity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
 		super.onCreate(savedInstanceState);

		addPreferencesFromResource(R.xml.settings);
	}

	private boolean validade(){
		if(getPreferenceManager().getSharedPreferences().getString("ip", null).isEmpty())
			return false;

		if(getPreferenceManager().getSharedPreferences().getString("usuario", null).isEmpty())
			return false;

		if(getPreferenceManager().getSharedPreferences().getString("senha", null).isEmpty())
			return false;

		if(getPreferenceManager().getSharedPreferences().getString("porta", null).isEmpty())
			return false;

		return true;
	}

	@Override
	public void onBackPressed() {
		if(validade()){
			setResult(1, getIntent());
			super.onBackPressed();
		}else{
			Toast.makeText(this, R.string.preencha_todos, Toast.LENGTH_LONG).show();
		}

	}
}
